package com.konsung.ksdc.common.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.konsung.ksdc.R;

/**
 * 权限提示框
 */
public class PermissionPopupWindow extends PopupWindow {
    private View view;
    TextView tvTitle;
    Button btnConfirm;

    /**
     * 构造方法
     * @param context 上下文
     * @param confirm 确认
     */
    public PermissionPopupWindow(Context context, View.OnClickListener confirm) {

        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context
                .LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.dialog_permission, null);
        tvTitle = (TextView) view.findViewById(R.id.tv_permiss_title);
        btnConfirm = (Button) view.findViewById(R.id.btn_dialog_ok);
        btnConfirm.setOnClickListener(confirm);
        //设置PopupWindow的View
        this.setContentView(view);
        //设置PopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体可点击
        this.setFocusable(false);
        this.getBackground().setAlpha(100);
    }

    /**
     * 设置弹窗标题
     * @param title 标题
     */
    public void setTitle(String title) {
        if (tvTitle != null) {

            tvTitle.setText(title);
        }
    }

    /**
     * 设置弹窗butoon
     * @param text 标题
     */
    public void setBtntext(String text) {
        if (btnConfirm != null) {
            btnConfirm.setText(text);
        }
    }
}
